package com.y.config.mybatisPlus;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 字段自动填充属性
 * @author: Yjh
 */

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        // 设置填充字段属性
        setFieldValByName("gmtCreate", LocalDateTime.now(),metaObject);
        setFieldValByName("gmtUpdate", LocalDateTime.now(),metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        // 更新填充字段属性
        setFieldValByName("gmtUpdate", LocalDateTime.now(),metaObject);
    }

}
